#include "Label.hpp"

namespace red {
	namespace ui {
		Label::Label(const std::string &pText)
		:	MovableWidget()
		{
			SetText(pText);
			SetColor(sf::Color(0,0,0,0));
		}

		void Label::SetText(const std::string &pText){
			mText.SetString(pText);
			OnUpdate(Size);
		}

		void Label::SetTextSize(u32 pSize){
			mText.SetCharacterSize(pSize);
			OnUpdate(Size);
		}

		void Label::OnRender(sf::RenderTarget &pTarget, sf::Renderer &pRenderer) const{
			// Draw possible background (and children);
			Widget::OnRender(pTarget, pRenderer);

			// Draw Text
			pRenderer.SetColor(mText.GetColor());
			pTarget.Draw(mText);
		}

		void Label::OnUpdate( WidgetParameter pParam ){
			switch(pParam){
			case Size:
				{
				f32 textWidth = mText.GetRect().Width;
				f32 textHeight = mText.GetRect().Height;

				if(textWidth != GetSize().x)
					mRectangle.SetWidth(textWidth);
				

				if(textHeight != GetSize().y)
					mRectangle.SetHeight(textHeight);
				
				}
				// No break !! (for border/children update)
			default:
				MovableWidget::OnUpdate(pParam);
			}
		}

	}
}